package com.hz.ruoyimotor.controller;




import com.hz.rouyigonggong.domain.LgSeller;
import com.hz.rouyigonggong.domain.LgVehicle;
import com.hz.rouyigonggong.domain.basedomain.BaseDomain;
import com.hz.rouyigonggong.utils.ResultJSON;
import com.hz.ruoyimotor.domain.dto.LgDriverDto;
import com.hz.ruoyimotor.service.LgVehicleService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author gj
 * @version 1.0
 * @date 2025/3/3 14:02
 */

@RestController
@RequestMapping("/vehicle")
public class LgVehicleController {
    @Autowired
    private LgVehicleService lgVehicleService;
    /**
     * 获取车辆列表
     */
    @RequiresPermissions("motor:vehicle:getAll")
    @RequestMapping("/getAll")
    public ResultJSON getAll(Integer vehicleType, Double vehicleLength,
                             Double vehicleVolume,
                             Integer licenseType,String licensePlate,
                             Integer vehicleStatus,
                             String beginTime,
                             String endTime, Integer pageNum, Integer pageSize){
        String createBy = String.valueOf(BaseDomain.getUserId());

        Integer firstNum = (pageNum-1)*pageSize;
        Integer secondNum = pageSize;


        //完成分页
        return ResultJSON.success(lgVehicleService.getReallyList(vehicleType, vehicleLength,
                vehicleVolume,
                licenseType,licensePlate,vehicleStatus,
                beginTime,
                endTime,
                firstNum,secondNum,createBy));

}
        //获取车辆总数
    @RequiresPermissions("motor:vehicle:getTotal")
    @RequestMapping("/getTotal")
    public ResultJSON getTotal(Integer vehicleType, Double vehicleLength, Double vehicleVolume,
                               Integer licenseType,String licensePlate,
                               String beginTime,
                               String endTime,  Integer vehicleStatus){
        String createBy = String.valueOf(BaseDomain.getUserId());
        return ResultJSON.success(lgVehicleService.getCount(vehicleType, vehicleLength,
                vehicleVolume,
                licenseType,licensePlate,
                beginTime,
                endTime,
                vehicleStatus,createBy));
    }
    //获得单个车辆
    @RequiresPermissions("motor:vehicle:getVehicleById")
    @GetMapping(value = "/{vehicleId}")
    public ResultJSON getVehicleById(@PathVariable Integer vehicleId){

        return ResultJSON.success(lgVehicleService.getById(vehicleId));
    }
    //添加车辆
    @RequiresPermissions("motor:vehicle:add")
    @PostMapping("/addVehicle")
    public ResultJSON addVehicle(@RequestBody LgVehicle lgVehicle){
        lgVehicle.setCreateBy(String.valueOf(BaseDomain.getUserId()));
        return ResultJSON.success(lgVehicleService.save(lgVehicle));
    }
    //修改车辆
    @RequiresPermissions("motor:vehicle:update")
    @PostMapping("/updateVehicle")
    public ResultJSON updateVehicle(@RequestBody LgVehicle lgVehicle){
        return ResultJSON.success(lgVehicleService.updateById(lgVehicle));
    }
    //删除车辆

    @RequiresPermissions("motor:vehicle:delete")
    @DeleteMapping("/{vehicleIds}")
    public AjaxResult delVehicle(@PathVariable String[] vehicleIds)
    {
        return AjaxResult.success(lgVehicleService.deleteBatchIds(vehicleIds));

    }
    @RequiresPermissions("motor:vehicle:export")
    @Log(title = "车辆", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LgVehicle lgVehicle)
    {

        List<LgVehicle> list = lgVehicleService.list(null);
        ExcelUtil<LgVehicle> util = new ExcelUtil<LgVehicle>(LgVehicle.class);
        util.exportExcel(response, list, "车辆数据");
    }

}





